﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Odbc;
using System.Data;
using System.Data.SqlClient;


/// <summary>
/// Summary description for Helper
/// </summary>

    public class Helper
    {
        private SqlConnection _conn = null;


        private SqlCommand GetCommand(string query)
        {
            string connectionString = "Data source=.;Initial catalog=sangtaotre;Integrated security=true";
            _conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(query, _conn);
            _conn.Open();
            return cmd;
        }

        public int ExecutNonQuery(string query) 
        {
            return GetCommand(query).ExecuteNonQuery();
        }

        public SqlDataReader ExecuteReader(string query) 
        {
            return GetCommand(query).ExecuteReader();
        }

        public DataTable GetTable(string query){
            SqlDataAdapter da = new SqlDataAdapter(GetCommand(query));
            DataTable dataTable = new DataTable();
            da.Fill(dataTable);
            return dataTable;
        }

        public Object ExecuteScalar(string query)
        {
            return GetCommand(query).ExecuteScalar();
        }
    }
    
